


	
project, uses(../data_output/termlimited.dta)
	

		use ../data_output/termlimited.dta	, clear			
		keep CandId chamber_term rating* sig_name* sig_issues* termlimited party terms_in_office state term year
		reshape long rating sig_name sig_issues, i(CandId chamber_term) j(sig_id)
		
		label define issues 1 "Abortion"  2	"Business" 3 "Education" 4 "Environment" 5 "Guns" 6 "Other" 7 "Taxes" 8 "Labor Unions"
		label values  sig_issues issues			
		
		drop if sig_name==999999
		keep if sig_name!=.
		gen obs = 1
		decode sig_name  , generate(group)
		replace group = subinstr(group, "&", "\&", .)
		
		decode sig_issues  , generate(issue)
		bys group: egen min_year = min(year)
		bys group: egen max_year = max(year)
		
	
		collapse (sum) obs (mean) min_year max_year, by(group issue state )
		
		replace state = state + " "
		sort group state
		bys group: gen n=_n
		reshape wide obs   state, i(group issue) j(n)
	
	
		egen states = concat(state*)
		gen range = string(min_year) +"-" +string(max_year)
		egen Obs = rowtotal(obs*)
		
		
		keep states range Obs group issue
		sort group
	
	
		quietly {
			cap log close
			set linesize 255
			log using "../tables_figures/sig_summary.tex", text replace
			
			noisily dis "\begin{table}[h]"
			noisily dis "\centering"
			noisily dis "\caption{\textbf{Interest Group Ratings}\label{tab:}"
			noisily dis	"}"
			noisily dis " \begin{adjustbox}{max width=\textwidth} "
			noisily dis "\begin{tabular}{l rrrr }"
			noisily dis "\toprule \toprule"
			
			noisily dis " Interest Group  & Issue Area & States    & Year Range    & Observations \\[2mm]"

			noisily dis " \cline{1-5}    \\ " 
		
			sum Obs
			local rows = r(N)
			gsort group
			forval i=1/ `rows' { 
				noisily dis  group[`i'] "&"  issue[`i']  "&"  states[`i'] "&" range[`i'] "&"%9.0fc Obs[`i']  "\\[1mm]"
				
			}		
			
			collapse (sum) Obs
			noisily dis "\midrule \\"

			noisily dis   " Total Legislator-Terms Ratings&"   "&"  "&"  "&"%9.0fc  Obs[1]  "\\[1mm]"

			
			
			
			noisily dis "\bottomrule \bottomrule"	
			noisily dis "\multicolumn{5}{p{\textwidth}}{\footnotesize "
			noisily dis "  }"
			noisily dis "\end{tabular}"
			noisily dis "\end{adjustbox}"	
			noisily dis "\end{table}"
			
			log off
		}
		
		